import { Badge } from 'antd'

import { addAGCellTexty } from '@oBiz/components/addTexty'
import { CellAction } from './Cell.Action'
import * as CellEdit from './Cell.Edit'
import { TCellParams } from './interface'

export const Cell = (p: TCellParams) => {
  const { field } = p.colDef || {}
  switch (field) {
    case 'publishStatus': {
      const { value, valueFormatted } = p as TCellParams<'publishStatus'>
      if (value == null) return
      return <Badge color={value === 1 ? 'green' : $CSS_VAR.statusDefault} text={valueFormatted || value} />
    }
    case 'occurDate': {
      return <CellEdit.OccurDateCell {...(p as TCellParams<'occurDate'>)} />
    }
    case 'keepDate': {
      return <CellEdit.KeepDateCell {...(p as TCellParams<'keepDate'>)} />
    }
    case 'fileList': {
      return <CellEdit.FileListCell {...(p as TCellParams<'fileList'>)} />
    }
    case 'publishId': {
      return <CellAction {...(p as TCellParams<'publishId'>)} />
    }
    default: {
      return addAGCellTexty(p)
    }
  }
}
